package com.demo2.todo.controller;

import com.demo2.todo.model.dto.ShareReviewRequest;
import com.demo2.todo.model.dto.ShareReviewResponse;
import com.demo2.todo.service.ShareReviewService;
import com.demo2.todo.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author evi
 */
@RestController
@RequestMapping("/admin/share-reviews")
@RequiredArgsConstructor
@PreAuthorize("hasRole('ADMIN')")
public class ShareReviewController {
    private final ShareReviewService shareReviewService;

    // 获取待审核的分享
    @GetMapping("/pending")
    public ResponseEntity<List<ShareReviewResponse>> getPendingReviews() {
        return ResponseEntity.ok(shareReviewService.getPendingReviews());
    }

    // 审核分享
    @PutMapping("/{id}/review")
    public ResponseEntity<ShareReviewResponse> reviewShare(
            @PathVariable Long id,
            @RequestBody ShareReviewRequest request) {
        return ResponseEntity.ok(shareReviewService.reviewShare(
                id, request, SecurityUtils.getCurrentUser()));
    }
}